﻿namespace N2.Workflow.Items
{
	using Details;
	using N2.Edit.Trash;
	using Integrity;
	using Persistence;

	/// <summary>
	/// A base class of a different workflow mapping mechanisms
	/// between Workflows and Content Items.
	/// </summary>
	[RestrictParents(typeof(WorkflowRepository))]
	[NotThrowable, NotVersionable]
	public abstract class WorkflowBinding: ContentItem
	{
		#region Properties
		/// <summary>
		/// Workflow definition to be associated with Content Items
		/// </summary>
		[EditableLink("Workflow", 1)]
		public Workflow Workflow {
			get { return this.GetDetail<Workflow>("Workflow", null); }
			set { this.SetDetail<Workflow>("Workflow", value); }
		}

		public override string Title {
			get { return base.Title ?? this.GetCaption(); }
		}

		public override bool IsPage { get { return false; } }

		#endregion Properties

		protected virtual string GetCaption()
		{
			return
				null != this.Workflow
					? this.Workflow.Title + "#" + this.Workflow.ID
					: "?";
		}
	}
}
